import React, { Component, Suspense } from "react";
import PageHeaderWrapper from "@/components/PageHeaderWrapper";

import { connect } from "dva";
import PageLoading from "@/components/PageLoading";
import { FormattedMessage,formatMessage } from "umi-plugin-react/locale";
import { Row, Col, Card, Icon, Form, Button, Input, Spin, Table, Modal, Radio, Pagination, message, Drawer, Tooltip, Tabs, Select } from "antd";
import { columnsTable } from "./wordData";
import styles from "./index.less";
import Service from "../../../modules/service";
import deleteimg from "@/assets/buttonimg/delete.png";
const { TabPane } = Tabs;
const FormItem = Form.Item;
const Search = Input.Search;
const RadioGroup = Radio.Group;
const MyIcon = Icon.createFromIconfontCN({
	scriptUrl: "//at.alicdn.com/t/font_1131883_m18hmgbwet.js", // 在 iconfont.cn 上生成
});
import ljx from "../../../assets/icons/垃圾箱.png";
import pen from "../../../assets/icons/bi.png";
import UserSession from "@/UserSession";
import tableDataCheck from "@/utils/isBackPrevPage";

@connect(({ wordTroughManage, loading }) => ({
	wordTroughManage,
	loading: loading.effects["wordTroughManage/fetch"],
}))
class WordTroughManage extends Component {
	constructor(props) {
		super(props);
		this.state = {
			total: 0,
			login: false,
			dataSource1: [],
			pageSizeA: 10,
			pageA: 1,
			pageSize: 10,
			page: 1,
			pageC: 1,
			pageSizeC: 10,
			addModel: false,
			wordName: "",
			wordAlias: "",
			visitWords: "",
			showModel: false,
			value: "none",
			onChantTable: 1,
			item: {},
			choice: [{ choiceType: "user", customs: [], plug: "tcx" }],
			personalityList: [],
			personalitytotal: "",
			editor: true,
			textOne: "",
			slotId: "",
			yeshua: 1,
			yeshub: 10,
			zhuvalue: "",
			close: false,
			dictType: "user",
			inputT: "",
			isEnum: true,
			isEnumTwo: null,
			wordType: "",
			tabKey: 1,
			entityCurrent: 1,
			entityLoading: false,
			dataSourceEntity: [],
			entityTotal: 0,
			currentEntity: null,
			entitySize: 10
		};
	}

	inSue = (item) => {
		let a = item;
		this.setState({ item: a }, () => this.openClose());
	};

	openClose = () => {
		this.setState({ close: true });
	};

	onClose = () => {
		this.setState({ close: false });
	};

	// eslint-disable-next-line react/sort-comp
	handleDelete = (a) => {
		//
		const { dispatch } = this.props;
		const { tabKey } = this.state;
		this.reqRef = requestAnimationFrame(() => {
			dispatch({
				type: "wordTroughManage/fetchf",
				payload: { id: a.id, urlPrefix: tabKey == 1 ? null : "headquarters" },
				callback: (res) => {
					// console.log(res);
					this.setState({
						isEnum: res.firstDictEnum,
						isEnumTwo: res.firstDictEnum ? true : false,
						wordType: res.type,
						currentEntity: {
							id: res.modelId,
							type: res.type
						}
					});
					if (res.choice.length === 0) {
						this.setState({
							value: "none",
							choice: [{ choiceType: "user", customs: [], plug: "tcx" }],
							addModel: true,
							wordName: res.keyName,
							wordAlias: res.name,
							visitWords: res.inquire,
							textOne: res.modelName,
							textId: res.modelId,
							editor: false,
							slotId: res.id,
							dictType: res.type,
							onChantTable: res.type == "sys" ? 2 : 1,
						});
					} else {
						let customslist = res.choice;
						if (customslist.length !== 0) {
							this.setState({ value: "user" });
						};
						let a = [];
						let customs = [];
						customslist.map((item, index) => {
							let maplist = { choiceType: "user", customs: [], plug: "tcx" };
							maplist.customs = [];
							maplist.customs.push(item);
							a.push(maplist);
						});
						for (let i = 0; i < a.length - 1; i++) {
							a[i].plug = "";
						};
						this.setState({ choice: a });

						this.setState({
							addModel: true,
							wordName: res.keyName,
							wordAlias: res.name,
							visitWords: res.inquire,
							textOne: res.modelName,
							textId: res.modelId,
							editor: false,
							slotId: res.id,
							dictType: res.type,
							onChantTable: res.type == "sys" ? 2 : 1,
						});
					}
				},
			});
		});
	};

	fetch = (page = 1, limit = 10, keys) => {
		this.setState({ login: true });
		const { dispatch, currentUser } = this.props;
		const { tabKey } = this.state;

		this.reqRef = requestAnimationFrame(() => {
			dispatch({
				type: "wordTroughManage/fetch",
				payload: {
					current: page,
					size: limit,
					search: keys ? keys : "",
					// urlPrefix: tabKey == 1 ? "" : "headquarters",
					type: tabKey,
				},
				callback: (res) => {
					let temp = res.records ? res.records : [];
					temp.map((item, index) => {
						item.nameTwo = item.keyName;
						item.key = index;
					});
					// temp.reverse()
					this.setState({
						dataSource1: temp,
						total: Number(res.total),
						login: false,
					});
				},
			});
		});
	};

	fetchd = () => {
		const { dispatch, currentUser } = this.props;
		const formInfo = this.props.form.getFieldsValue()
		this.reqRef = requestAnimationFrame(() => {
			dispatch({
				type: "wordTroughManage/basicDictSysList",
				payload: { search: formInfo.query },
				callback: (res) => {
					let temp = res;
					this.setState({
						dataSourceEntity: res,
						entityLoading: false,
						entityTotal: res.length,
						entitySize: res.length
					});
				},
			});
		});
	};

	// 自定义实体
	fetche = () => {
		const { dispatch } = this.props;
		dispatch({
			type: "wordTroughManage/basicDictList",
			payload: {
				current: this.state.pageC,
				size: this.state.pageSizeC,
				search: this.state.inputT,
			},
			callback: (res) => {
				res.records.map((item, index) => {
					item["key"] = index;
				});
				this.setState({
					personalityList: res.records,
					personalitytotalC: Number(res.total),
					login: false,
				});
			},
		});
	};

	componentDidMount() {
		this.fetch();
	}

	onChangeB = (e) => {
		this.setState({ yeshua: e }, () => {
			this.fetch(this.state.yeshua, this.state.yeshub, this.state.zhuvalue);
		});
	};

	onShowSizeChangeB = (va, vb) => {
		this.setState({ yeshub: vb, yeshua: va }, () => {
			this.fetch(this.state.yeshua, this.state.yeshub, this.state.zhuvalue);
		});
		// this.fetch(va, vb, '')
	};

	beginFrom = () => {
		this.props.form.setFields({ wordName: "" });
		this.props.form.setFields({ wordAlias: "" });
		this.props.form.setFields({ visitWords: "" });

		this.setState({ textId: "" });
	};

	queryEntity = current => {
		this.setState({ entityCurrent: current }, () => {
			this.getEntityList()
		})
	}

	getEntityList = () => {
		this.setState({ entityLoading: true }, () => {
			const formInfo = this.props.form.getFieldsValue()
			// console.log(formInfo);
			if (formInfo.type == 0) {
				this.getCustomEntity()
			} else if (formInfo.type == 1) {
				this.getSysEntity()
			} else {
				this.fetchd()
			}
		})
	}

	getCustomEntity = () => {
		const { dispatch, currentUser } = this.props;
		const { entityCurrent } = this.state;
		const formInfo = this.props.form.getFieldsValue()
		this.reqRef = requestAnimationFrame(() => {
			dispatch({
				type: "antistopReply/fetche",
				payload: { current: entityCurrent, size: 10, search: formInfo.query },
				callback: (res) => {
					this.setState({
						dataSourceEntity: res.records,
						entityLoading: false,
						entityTotal: res.total,
						entitySize: 10
					});
				},
			});
		});
	}

	getSysEntity = () => {
		const { dispatch, currentUser } = this.props;
		const { entityCurrent } = this.state;
		const formInfo = this.props.form.getFieldsValue()
		this.reqRef = requestAnimationFrame(() => {
			dispatch({
				type: "customDictionary/fetch",
				payload: {
					current: entityCurrent,
					size: 10,
					search: formInfo.query,
					urlPrefix: 'headquarters',
				},
				callback: (res) => {
					this.setState({
						dataSourceEntity: res.records,
						entityLoading: false,
						entityTotal: res.total,
						entitySize: 10
					})
				},
			});
		});
	}

	chooseEntity = text => {
		this.setState({
			showModel: false,
			textOne: text.name,
			textId: text.id,
			editor: false,
			isEnum: text.isEnum,
			wordType: text.type ? text.type : "",
			currentEntity: text
		});
	}

	closeEntity = () => {
		this.props.form.setFieldsValue({ type: 0 })
		this.setState({
			showModel: false,
			onChantTable: 1,
			// currentEntity: null
		});
	}

	render() {
		const { tabKey, entityCurrent, entityLoading, entityTotal, dataSourceEntity, currentEntity, entitySize, zhuvalue } = this.state;
		let operationDate = [
			{
				title: <FormattedMessage id='app.wordTroughManage.word-name' />,
				dataIndex: "keyName",
				width: "calc(18vw)",
			},
			{
				title: <FormattedMessage id='app.wordTroughManage.word-alias' />,
				dataIndex: "name",
				width: "calc(18vw)",
			},
			{
				title: <FormattedMessage id='app.wordTroughManage.dictionary' />,
				dataIndex: "modelName",
				width: "calc(18vw)",
			},
			{
				title: <FormattedMessage id='app.wordTroughManage.operation' />,
				render: (text, item) => {
					return (
						<div className={styles.pb}>
							<div
								className={styles.buttongl}
								// onClick={text => this.handleDelete(item)}><MyIcon style={{ marginRight: 5 }} type="icon-bi" /><FormattedMessage id="app.wordTroughManage.edit" />
								onClick={text => this.handleDelete(item)}
							>
								<img src={pen} style={{ marginRight: 5 }} />
								<span style={{ marginBottom: 1 }}>
									<FormattedMessage id='app.wordTroughManage.edit' />
								</span>
							</div>
							<div
								style={{ marginLeft: 10, background: "#e8313b" }}
								className={styles.buttongl}
								onClick={text => this.handleDeletes(item)}
							>
								<img src={deleteimg} style={{ marginRight: 5 }} />
								<span style={{ marginBottom: 1 }}>
									<FormattedMessage id='app.wordTroughManage.delete' />
								</span>
							</div>
							{item.isUsing ? (
								<div
									className={styles.buttongl}
									onClick={text => this.inSue(item)}
									style={{ marginLeft: 10, background: "#09B2FF" }}
								>
									<img src={staticPath + "/useing.svg"} style={{ marginRight: 5 }} />
									<span style={{ marginBottom: 1 }}>
										<FormattedMessage id='app.wordTroughManage.in-use' />
									</span>
								</div>
							) : null}
						</div>
					);
				},
			},
		];
		const { getFieldDecorator } = this.props.form;
		const FormItemLayont = {
			labelCol: { xs: 24, sm: 5 },
			wrapperCol: { xs: 24, sm: 19 },
		};

		let urlPrefix = "";
		if (tabKey == 2) {
			urlPrefix = "headquarters";
		};

		if (tabKey == 2) {
			operationDate = [
				{
					title: <FormattedMessage id='app.wordTroughManage.word-name' />,
					dataIndex: "keyName",
					width: "calc(18vw)",
				},
				{
					title: <FormattedMessage id='app.wordTroughManage.word-alias' />,
					dataIndex: "name",
					width: "calc(18vw)",
				},
				{
					title: <FormattedMessage id='app.wordTroughManage.dictionary' />,
					dataIndex: "modelName",
					width: "calc(18vw)",
				},
				{
					title: <FormattedMessage id='app.wordTroughManage.operation' />,
					render: (text, item) => {
						return (
							<div className={styles.pb}>
								<div
									className={styles.buttongl}
									onClick={text => this.handleDelete(item)}>
									<img src={pen} style={{ marginRight: 5 }} />
									<span style={{ marginBottom: 1 }}>
										<FormattedMessage id='app.wordTroughManage.view' />
									</span>
								</div>

								{item.isUsing ? (
									<div
										className={styles.buttongl}
										onClick={text => this.inSue(item)}
										style={{ marginLeft: 10, background: "#09B2FF" }}
									>
										<img src={staticPath + "/useing.svg"} style={{ marginRight: 5 }} />
										<span style={{ marginBottom: 1 }}>
											<FormattedMessage id='app.wordTroughManage.in-use' />
										</span>
									</div>
								) : null}
							</div>
						);
					},
				},
			];
		}

		const columnsEntity = [
			{
				title: <FormattedMessage id='app.wordTroughManage.entity-name' />,
				dataIndex: 'name'
			},
			{
				title: <FormattedMessage id='app.wordTroughManage.operation' />,
				width: 100,
				render: (text, row) => {
														return currentEntity && row.id === currentEntity.id ? <Button disabled size="small"><FormattedMessage id='app.wordTroughManage.selected' /></Button> : <Button size="small" type="primary" onClick={() => this.chooseEntity(row)}><FormattedMessage id='app.wordTroughManage.select' /></Button>
				}
			}
		]

		return (
			<Suspense fallback={<PageLoading />}>
				<PageHeaderWrapper>
					<Card bordered={false} style={{ height: '100%' }}>
						<div>
							<Row className='zdyButtonA'>
								<Col span={16}>
									<Input
										placeholder={formatMessage({ id: 'app.wordTroughManage.search.placeholder' })}
										onClick={e => this.setState({ yeshua: 1, zhuvalue: e.target.value })}
										style={{ width: 324, marginRight: 10 }}
										value={zhuvalue}
										onChange={(e) => this.setState({ zhuvalue: e.target.value })}
									/>
									<Button type="primary" onClick={() => this.setState({ yeshua: 1 }, () => this.fetch(this.state.yeshua, this.state.yeshub, this.state.zhuvalue))}>
										<FormattedMessage id='app.wordTroughManage.search' />
									</Button>
								</Col>
								<Col span={8} style={{ textAlign: 'right' }}>
									<Button type='primary' onClick={() => this.newWordTrough()}>
										<FormattedMessage id='app.wordTroughManage.add' />
									</Button>
								</Col>
							</Row>
							<div className='tableyc'>
								<Spin spinning={this.state.login}>
									<Table
										className='zdyTable'
										rowKey={'id'}
										style={{ padding: "20px 0px 0px 0px" }}
										columns={operationDate}
										dataSource={this.state.dataSource1} //数据
										pagination={false}
									/>
									{this.state.total > 10 ? (
										<Pagination
											style={{ textAlign: 'right', marginTop: 16 }}
											total={this.state.total}
											pageSize={this.state.yeshub}
											current={this.state.yeshua}
											// showSizeChanger={true}
											showQuickJumper={true}
											onChange={this.onChangeB}
											// onShowSizeChange={this.onShowSizeChangeB}
										/>
									) : null}
								</Spin>
							</div>
						</div>

						<Drawer
							className='modelZdy'
							title={<FormattedMessage id='app.wordTroughManage.add-edit-slots' />}
							visible={this.state.addModel}
							width={600}
							headerStyle={{ background: "#F7F9FD", borderBottom: 0 }}
							onClose={() => {
								this.setState({ addModel: false, editor: true, onChantTable: 1, slotId: "", });
								this.beginFrom();
							}}
						>
							<div>
								<Form
									className='zdyxin'
									layout='horizontal'
									labelCol={{
										xs: { span: 24 },
										sm: { span: 2 },
									}}
									wrapperCol={{
										xs: { span: 24 },
										sm: { span: 22 },
									}}
								>
									<FormItem
										label={<FormattedMessage id='app.wordTroughManage.word-name' />}
										className={styles.wardfrom}
										{...FormItemLayont}
									>
										{getFieldDecorator("wordName", {
											initialValue: `${this.state.wordName}`,
											rules: [
												{ required: true, message: formatMessage({ id: 'app.wordTroughManage.entity-name.required' }) },
												{
													pattern: /^[0-9a-zA-Z._]*$/g,
													message: formatMessage({id: 'app.wordTroughManage.input-pattern'}),
												},
											],
										})(
											<Input
												placeholder={formatMessage({ id: 'app.wordTroughManage.entity-name.pattern' })}
												maxLength={100}
												disabled={this.state.slotId}
											/>
										)}
									</FormItem>
									<FormItem
										label={<FormattedMessage id='app.wordTroughManage.word-alias' />}
										className={styles.wardfrom}
										{...FormItemLayont}
									>
										{getFieldDecorator("wordAlias", {
											initialValue: `${this.state.wordAlias}`,
											rules: [
												{ required: true, message: formatMessage({ id: 'app.wordTroughManage.word-alias.required' }) },
											],
											getValueFromEvent: (event) => event.target.value.replace(/\s+/g, ""),
										})(
											<Input placeholder={formatMessage({ id: 'app.wordTroughManage.word-alias.placeholder' })} />
										)}
									</FormItem>
									<FormItem
										label={<FormattedMessage id='app.wordTroughManage.corresponding-dictionary' />}
										className={styles.wardfrom}
										{...FormItemLayont}
									>
										{getFieldDecorator("wordAliase", {
											initialValue: `${this.state.textOne}`,
											rules: [{ required: true }],
										})(
											<div>
												{this.state.editor == true || this.state.textOne === null ? (
													<Button style={{ marginRight: 5 }} size='small' onClick={this.newModal}>
														<FormattedMessage id='app.wordTroughManage.add-button' />
													</Button>
												) : (
													<span>
														<span style={{ marginRight: 12 }}>{this.state.textOne}</span>
														{this.state.isEnumTwo && this.state.wordType != "sys" ? (
															<Button onClick={this.message} style={{ marginRight: 5 }} size='small'>
																<FormattedMessage id='app.wordTroughManage.edit' />
															</Button>
														) : null}
													</span>
												)}
												<Button disabled={tabKey == 2} onClick={this.newModal} size='small'>
													<FormattedMessage id='app.wordTroughManage.change' />
												</Button>
											</div>
										)}
									</FormItem>
									<FormItem 
										label={<FormattedMessage id='app.wordTroughManage.inquiry-speech' />} 
										className={styles.wardfrom} 
										{...FormItemLayont}
									>
										{getFieldDecorator("visitWords", {
											initialValue: `${this.state.visitWords}`,
											rules: [{ required: true, message: formatMessage({ id: 'app.wordTroughManage.inquiry-speech.required' }) }],
										})(
											<Input placeholder={formatMessage({ id: 'app.wordTroughManage.inquiry-speech.placeholder' })} />
										)}
									</FormItem>
									<FormItem 
										label={<FormattedMessage id='app.wordTroughManage.additional-options' />} 
										className={styles.wardfrom} 
										{...FormItemLayont}
									>
										<RadioGroup onChange={this.onChange} value={this.state.value}>
											<Radio value={"none"}>
												<FormattedMessage id='app.wordTroughManage.automatic' />
											</Radio>
											<Radio value={"user"}>
												<FormattedMessage id='app.wordTroughManage.value-options' />
											</Radio>
										</RadioGroup>
									</FormItem>
									{this.state.value === "none" ? "" : this.state.choice.map((item, index) => {
										return (
											<div className={styles.maginrht} style={{ marginLeft: 115 }}>
												<Form layout='inline' style={{ marginBottom: 10 }}>
													<FormItem>
														<Input
															maxLength={20}
															style={{ width: 330 }}
															value={item.customs[0]}
															onChange={(e) => this.busChange(e, index)}
														/>
													</FormItem>
													<FormItem>
														{item.plug === "tcx" ? (
															<Button onClick={() => this.handleSubmitA(index)}>添加</Button>
														) : (
															<img src={ljx} onClick={() => this.handleSubmitAs(index)} />
														)}
													</FormItem>
												</Form>
											</div>
										);
									})}
								</Form>
							</div>

							<div
								style={{
									position: 'absolute',
									right: 0,
									bottom: 0,
									width: '100%',
									borderTop: '1px solid #e9e9e9',
									padding: '10px 16px',
									background: '#fff',
									textAlign: 'right',
								}}
							>
								<Button onClick={() => { this.setState({ addModel: false, editor: true, onChantTable: 1, slotId: "", }); this.beginFrom(); }} style={{ marginRight: 8 }}>
									<FormattedMessage id='app.common.cancel' />
								</Button>
								<Button onClick={this.operation} disabled={tabKey == 2} type="primary">
									<FormattedMessage id='app.common.confirm' />
								</Button>
							</div>
						</Drawer>
						<Modal
							className='modelZdy'
							title={<FormattedMessage id='app.wordTroughManage.select-entity' />}
							visible={this.state.showModel}
							footer={null}
							okText='保存'
							cancelText='取消'
							onCancel={this.closeEntity}
							width={600}
						>
							<div style={{ maxHeight: 700, overflow: 'auto' }}>
								<Form layout="inline" style={{ marginBottom: 20 }}>
									<FormItem>
										{
											getFieldDecorator('type', { initialValue: 0 })(
																									<Select style={{ width: 110 }} onChange={() => this.queryEntity(1)}>
																										<Select.Option value={0}>
																											<FormattedMessage id='app.wordTroughManage.custom-entity' />
																										</Select.Option>
																										<Select.Option value={2}>
																											<FormattedMessage id='app.wordTroughManage.system-entity' />
																										</Select.Option>
																									</Select>
											)
										}
									</FormItem>
									<FormItem>
										{getFieldDecorator('query')(<Input placeholder={formatMessage({id: 'app.wordTroughManage.entity-name.placeholder'})} />)}
									</FormItem>
									<FormItem>
										<Button type="primary" onClick={() => this.queryEntity(1)}>
											<FormattedMessage id='app.wordTroughManage.search' />
										</Button>
									</FormItem>
									<FormItem>
										<Button type='primary' onClick={this.addDictionary}>添加实体</Button>
									</FormItem>
								</Form>

								<Table
									rowKey={'id'}
									columns={columnsEntity}
									loading={entityLoading}
									dataSource={dataSourceEntity}
									pagination={{
										total: entityTotal,
										current: entityCurrent,
										onChange: this.queryEntity,
										pageSize: entitySize
									}}
								/>
							</div>
						</Modal>
						<Drawer
							title={<FormattedMessage id='app.wordTroughManage.slot-usage' />}
							placement='right'
							closable
							onClose={this.onClose}
							visible={this.state.close}
							width={800}
							destroyOnClose
						>
							<Service item={this.state.item} urlPrefix={urlPrefix}></Service>
						</Drawer>
					</Card>
				</PageHeaderWrapper>
			</Suspense>
		);
	}

	newWordTrough = () => {
		this.setState({
			addModel: true,
			editor: true,
			wordName: "",
			wordAlias: "",
			visitWords: "",
			choice: [{ choiceType: "user", customs: [], plug: "tcx" }],
			value: "none",
			currentEntity: null
		});
		this.beginFrom();
	};

	operation = () => {
		if (!this.state.editor && this.state.textOne !== null) {
			// 判断对应词典是否为空
			let userInfo = this.props.form.getFieldsValue();
			this.props.form.validateFields((err, values) => {
				if (!err) {
					let arr = this.state.choice;
					let ayy = {};
					let att = [];
					arr.map((item, index) => {
						att.push(item.customs.join());
					});

					if (this.state.value === "none") {
						ayy.customs = [];
					} else {
						if (att[0] == "") {
							ayy.choiceType = "none";
							ayy.customs = att;

							return message.error("附加选项 -> 自定义选项为空！");
						} else {
							ayy.choiceType = "user";
							ayy.customs = att;

							let listData = [];
							ayy.customs.map((item) => {
								if (item.length !== 0) {
									listData.push(item);
								}
							});
							ayy.customs = listData;
						}
					}

					const { dispatch, currentUser } = this.props;
					// console.log(this.state.dictType);
					let obj = {
						modelId: this.state.textId,
						keyName: userInfo.wordName,
						name: userInfo.wordAlias,
						inquire: userInfo.visitWords,
						choice: ayy.customs,
						type: this.state.currentEntity.type ? this.state.currentEntity.type : 'sys',
					};
					let url = "wordTroughManage/fetchb";
					if (this.state.slotId) {
						obj.id = this.state.slotId;
						url = "wordTroughManage/fetchEdit";
					};
					this.reqRef = requestAnimationFrame(() => {
						dispatch({
							type: url,
							payload: obj,
							callback: (res) => {
								if (typeof res.code !== 'undefined' && res.code !== 0) {
									// message["error"](`${res.message}`);
								} else {
									this.props.form.setFieldsValue({ type: 0 })
									this.setState({
										value: "none",
										addModel: false,
										slotId: "",
										wordName: "",
										wordAlias: "",
										visitWords: "",
										editor: true,
										choice: [{ choiceType: "user", customs: [], plug: "tcx" }],
										currentEntity: null
									});
									this.beginFrom();
									message.info(res.message);
									this.fetch(this.state.yeshua, this.state.yeshub, this.state.zhuvalue);
									this.setState({ value: "none", onChantTable: 1 });
								}
							},
						});
					});
				}
			});
		} else {
			message.error("请添加对应实体后再保存");
		}
	};

	newModal = () => {
		const that = this;
		this.setState({ showModel: true }, () => that.getEntityList());
	};

	onChange = (e) => {
		this.setState({ value: e.target.value });
	};

	busChangetwo = (e) => { };

	onChantTable = (e) => {
		if (e.target.value === 2) {
			this.props.form.setFields({ seektk: "" });
			this.setState({ dictType: "sys", page: 1, pageSize: 10, inputT: "" }, () => this.fetchd());
		};
		if (e.target.value === 1) {
			this.props.form.setFields({ seektk: "" });
			this.setState({ dictType: "user", pageC: 1, pageSizC: 10, inputT: "" }, () => this.fetche());
		};
		this.setState({ onChantTable: e.target.value });
	};

	onChangeA = (a) => {
		this.setState({ page: a });
		this.fetchd(this.state.dictType, a, "", "");
	};

	onShowSizeChangeA = (a, b) => {
		this.fetchd(this.state.dictType, a, b, "");
		this.setState({ page: a, pageSize: b });
	};

	onChangeC = (a) => {
		this.setState({ pageC: a }, () => this.fetche());
	};

	onShowSizeChangeC = (a, b) => {
		this.setState({ pageC: a, pageSizeC: b }, () => [this.fetche()]);
	};

	addDictionary = () => {
		const { textId, textOne, isEnum } = this.state;
		const w = window.open("about:blank");
		console.log(textId, textOne, isEnum);
		w.location.href = `/knowledgeDesign/customDictionary`;
	};

	message = () => {
		const { textId, textOne, isEnum } = this.state;
		const w = window.open("about:blank");
		if (isEnum) {
			w.location.href = `/knowledgeDesign/customDictionary/enumerable?${textId}&${textOne}`;
			this.setState({ addModel: false });
		} else {
			w.location.href = `/knowledgeDesign/customDictionary/noEnumerationNew?${textId}&${textOne}`;
			this.setState({ addModel: false });
		}
	};

	handleSubmitA = (index) => {
		let arr = this.state.choice;
		if (arr.length > 49) {
			message.error("自定义选项个数不能超过50条");
			return;
		};
		let dictItems = {
			wchoiceType: this.state.value,
			customs: [],
			plug: "tcx",
		};
		arr.push(dictItems);

		this.setState({ choice: arr });
		if (index > 0) {
			arr[index].plug = "";
		};
		arr[index].plug = "";
	};

	//删除
	handleSubmitAs = (index) => {
		let arr = this.state.choice;
		arr.splice(index, 1);

		this.setState({ choice: arr });
		// this.props.form.resetFields();
	};

	handleDeletes = (val) => {
		let text;
		if (val.isUsing) {
			Modal["confirm"]({
				title: `删除【${val.name}】任务`,
				content: "该词槽正在被使用中，删除后将影响机器人的正常问答，是否确定删除",
				okText: "删除",
				cancelText: "取消",
				onOk: () => {
					const { dispatch } = this.props;
					this.reqRef = requestAnimationFrame(() => {
						dispatch({
							type: "wordTroughManage/fetchc",
							payload: { id: val.id },
							callback: (res) => {
								message["info"](`${res.message}`);
								const { dataSource1, yeshua } = this.state;
								const newCurrent = tableDataCheck(dataSource1, yeshua, [val.id]);
								this.setState({ yeshua: newCurrent }, () => {
									this.fetch(this.state.yeshua, this.state.yeshub, this.state.zhuvalue);
								});
							},
						});
					});
				},
				onCancel() { },
			});
		} else {
			Modal["confirm"]({
				title: `删除【${val.name}】任务`,
				content: "是否确定删除该词槽",
				okText: "删除",
				cancelText: "取消",
				onOk: () => {
					const { dispatch } = this.props;
					this.reqRef = requestAnimationFrame(() => {
						dispatch({
							type: "wordTroughManage/fetchc",
							payload: { id: val.id },
							callback: (res) => {
								message["info"](`${res.msg}`);
								const { dataSource1, yeshua } = this.state;
								const newCurrent = tableDataCheck(dataSource1, yeshua, [val.id]);
								this.setState({ yeshua: newCurrent }, () => {
									this.fetch(this.state.yeshua, this.state.yeshub, this.state.zhuvalue);
								});
							},
						});
					});
				},
				onCancel() { },
			});
		}
	};

	busChange = (e, index) => {
		let arr = this.state.choice;
		arr[index].customs = [];
		arr[index].customs.push(e.target.value);
		this.setState({ choice: arr, choiceType: "user" });
	};
}

export default connect(({ user }) => ({
	// 全局数据
	currentUser: user.currentUser,
}))(Form.create()(WordTroughManage));